<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />

    <!-- 数据列表 -->
    <el-card class="box-card mt10" :body-style="{ padding: '5px 10px 5px' }">
      <div slot="header" class="mb9 f16">
        <span style="font-weight: 600">出货明细资料</span>
      </div>
      <Table :tableHeader="tableHeader" :tableData="tableData"></Table>
      <!-- 分页器 -->
      <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-card>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, watch } from 'vue'
import { reactive, ref } from 'vue'
import 'dayjs/locale/zh-cn'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'Shippinginformation'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { TableList, selectList, type TableListType } from '@/plugins/mixin'
import Api from '@/api/GeneralManager/inquire/Shippinginformation'
const imgList = ref<string[]>([])

const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入货号',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '客户交期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '出货日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const tableHeader = ref([
  {
    width: '140px',
    label: '出货单号',
    prop: 'shipSlipNo'
  },
  {
    width: '140px',
    label: '指令号',
    prop: 'lotNo'
  },
  {
    label: '品牌',
    prop: 'brand'
  },
  {
    width: '120px',
    label: '货号',
    prop: 'customStyle'
  },
  {
    width: '140px',
    label: '颜色',
    prop: 'styleColor'
  },
  {
    label: '样品类型',
    prop: 'orderType'
  },
  {
    label: '号码',
    prop: 'sizeNo'
  },
  {
    label: '订单数量',
    prop: 'orderQty'
  },
  {
    label: '客户交期',
    prop: 'deliveryDate'
  },
  {
    label: '出货数量',
    prop: 'prodQty'
  },
  {
    width: '140px',
    label: '扫描时间 / 出货时间',
    prop: 'prodTime'
  },
  {
    label: '采集员',
    prop: 'prodUserName'
  },
  {
    type: 'img',
    label: '图片',
    fixed: true,
    prop: 'photoPath',
    srcList: imgList
  }
])
// 表格数据
const tableData = ref([])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(658)

const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
const getTableList = async () => {
  let { Data, dataList, srcList } = (await TableList(formList, Api.getTableList, currentPage.value, pageSize.value)) as TableListType
  tableData.value = dataList
  total.value = Data.total
  imgList.value = srcList
}
const getSelectList = async () => {
  await selectList(formList, Api.getSelectList)
}
onMounted(async () => {
  getTableList()
  getSelectList()
})

const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
      item.dateValue = ''
    })
    getTableList()
  }
  if (content === '导出') {
    // const res = await fileRequest.post('/pcOrder/downloadPcAggSchedule') as any
    // const link = document.createElement("a"); // 利用a标签自定义下载文件名
    // let blob = new Blob([res.data]); // 创建Blob对象，设置文件类型
    // link.style.display = "none";
    // //设置连接
    // link.href = window.URL.createObjectURL(blob);
    // const FileName = decodeURI(res.headers['content-disposition'].split(`utf-8''`)[1])
    // link.download = FileName;//自定义文件名字
    // document.body.appendChild(link);
    // //模拟点击事件
    // link.click();
    // document.body.removeChild(link);
  }
}

watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
</script>

<style lang="less" scoped></style>
